package com.doitedu.hbase.client2;

import com.doitedu.hbase.utils.HbaseUtil;
import org.apache.hadoop.hbase.CompareOperator;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.filter.BinaryComparator;
import org.apache.hadoop.hbase.filter.FilterList;
import org.apache.hadoop.hbase.filter.QualifierFilter;
import org.apache.hadoop.hbase.filter.ValueFilter;

import java.util.Iterator;

/**
 * @Date 2021/12/16
 * @Created by HANGGE
 * @Description TODO
 */
public class C02_Filter03 {
    public static void main(String[] args) throws Exception {
        Connection conn = HbaseUtil.getConnection();
        Table tbl = HbaseUtil.getTable("tb_teacher", conn);
        Scan scan = new Scan();
        // 设置过滤器 , 过滤数据
        /**
         * 参数一  运算符  >=  <=  > <  = !=
         */
        ValueFilter valueFilter = new ValueFilter(CompareOperator.EQUAL, new BinaryComparator("lny".getBytes()));
        QualifierFilter qualifierFilter = new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator("job".getBytes()));
        //不能重复的set  覆盖
       /* //设置属性
        scan.setFilter(qualifierFilter);
        //设置值
        scan.setFilter(valueFilter);*/
        FilterList filterList = new FilterList();
        filterList.addFilter(qualifierFilter);
        filterList.addFilter(valueFilter);

        scan.setFilter(filterList);


        //扫描数据
        ResultScanner scanner = tbl.getScanner(scan);
        Iterator<Result> iterator = scanner.iterator();
        while (iterator.hasNext()){
            Result result = iterator.next();
            HbaseUtil.show(result);
        }

        tbl.close();
        conn.close();

    }
}
